package com.atguigu.redis7.service;

import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.UUID;
import java.util.concurrent.ThreadLocalRandom;

/**
 * @版本： V5.1.0
 * @版权： Copyright @ 2025 广东广昱信息科技有限公司版权所有
 * @作者： 广东广昱信息科技有限公司
 * @日期： 2025-07-12 18:05
 */
@Service
@Slf4j
public class OrderService {

    public static final String ORDER_KEY = "ord:";

    @Resource
    private RedisTemplate redisTemplate;
//    private StringRedisTemplate redisTemplate;

    public void addOrder(){
        int keyId = ThreadLocalRandom.current().nextInt(1000)+1;
        String serialNo = UUID.randomUUID().toString();
        String key = ORDER_KEY + keyId;
        String value = "京东订单"+serialNo;
        redisTemplate.opsForValue().set(key,value);
        log.info("****key:{}",key);
        log.info("****value:{}",value);
    }
    public String getOrderById(Integer keyId){
        String key = ORDER_KEY + keyId;
        String value =  (String)redisTemplate.opsForValue().get(key);
        log.info("****key:{}",key);
        log.info("****value:{}",value);
        return value;
    }
}
